<?php

namespace App\Mini;

use App\Http\Controllers\Controller;
use App\Http\Requests\MiniRequest;
use App\Http\Resources\MiniResource;
use App\Models\Mini;
use App\Models\Site;
use Illuminate\Http\Request;

/**
 * 小程序管理
 * @package App\Mini
 */
class MiniController extends Controller
{
    public function index(Site $site)
    {
        return MiniResource::collection($site->minis);
    }

    public function store(MiniRequest $request, Site $site, Mini $mini)
    {
        $mini = $site->minis()->create($request->input());
        return $this->message('添加成功', new MiniResource($mini));
    }

    public function show(Mini $mini)
    {
        return new MiniResource($mini);
    }

    public function update(MiniRequest $request, Mini $mini)
    {
        $mini->fill($request->input())->save();
        return $this->message('更新成功', new MiniResource($mini));
    }

    public function destroy(Mini $mini)
    {
        $mini->delete();
        return $this->message('删除成功');
    }
}
